﻿/*
NAILSUPERSTORE ® COMPANY
 
[HISTORY]
Created By  	: NGUYEN VAN TY
Created Date	: 18/01/2011
Modified By     :
Modified Date   :
Note            :

*/

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using CommonTagTime;
using CommonTagTime.ModelObject;
using CommonTagTime.Business;
namespace CommonTagTime.DataAccess
{
    public class daoZone
    {
        public daoZone()
        {

        }
        public ZoneCollection List(int CategoryId)
        {
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            SqlDataReader de;
            ZoneCollection items = new ZoneCollection();
            try
            {
                para[0] = new SqlParameter("CategoryId", SqlDbType.Int);
                para[0].Value = CategoryId;

                de = clsSQL.SPDataReader("Zone_List", para);               
                while (de.Read())
                {
                    Zone item = Load(de);
                    items.Add(item);
                }

                de.Close();
                de.Dispose();
            }
            catch (Exception e)
            {
                clsFile.WriteLog("daoZone", "List()", e.ToString());
            }
            finally
            {
                de = null;
                clsSQL.Dispose();
                clsSQL = null;
            }

            return items;
        }

        public ZoneCollection ListAll()
        {
            clsSQL clsSQL = new clsSQL();
            SqlDataReader de;
            ZoneCollection items = new ZoneCollection();
            try
            {
                de = clsSQL.SPDataReader("Zone_ListAll");
                while (de.Read())
                {
                    Zone item = Load(de);
                    items.Add(item);
                }

                de.Close();
                de.Dispose();
            }
            catch (Exception e)
            {
                clsFile.WriteLog("daoZone", "ListAll()", e.ToString());
            }
            finally
            {
                de = null;
                clsSQL.Dispose();
                clsSQL = null;
            }

            return items;
        }

        private Zone Load(IDataReader de)
        {
            Zone item = new Zone();
            item.ZoneId = clsConvert.DbToInt("ZoneId", de);
            item.Name = clsConvert.DbToString("Name", de);
            return item;
        }

        /// <summary>
        /// Move item up
        /// </summary>
        public bool OrderUp(int ZoneID)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            try
            {
                para[0] = new SqlParameter(busZone.ZoneId, SqlDbType.Int);
                para[0].Value = ZoneID;
                result = clsSQL.SPExecute("Zone_OrderUp", para);

            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoZone", "Zone_OrderUp(int ZoneID)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }

        /// <summary>
        /// Move item down
        /// </summary>
        public bool OrderDown(int ZoneID)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            try
            {
                para[0] = new SqlParameter(busZone.ZoneId, SqlDbType.Int);
                para[0].Value = ZoneID;
                result = clsSQL.SPExecute("Zone_OrderDown", para);
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoZone", "OrderDown(int ZoneID)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }

        public bool Active(int ZoneID)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            try
            {
                para[0] = new SqlParameter(busZone.ZoneId, SqlDbType.Int);
                para[0].Value = ZoneID;
                result = clsSQL.SPExecute("Zone_Active", para);

            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoZone", "Active(int ZoneID)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }

        public bool DeActive(int ZoneID)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            try
            {
                para[0] = new SqlParameter(busZone.ZoneId, SqlDbType.Int);
                para[0].Value = ZoneID;
                result = clsSQL.SPExecute("Zone_DeActive", para);
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoZone", "DeActive(int ZoneID)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }

        public bool Delete(int ZoneID)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            try
            {
                para[0] = new SqlParameter(busZone.ZoneId, SqlDbType.Int);
                para[0].Value = ZoneID;
                result = clsSQL.SPExecute("Zone_Delete", para);
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoZone", "Delete(int ZoneID)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }

        public bool Insert(Zone objZone)
        {

            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[1];
            try
            {
                para[0] = new SqlParameter(busZone.Name, SqlDbType.NVarChar);
                para[0].Value = clsConvert.StringToDB(objZone.Name);
               
                result = clsSQL.SPExecute("Zone_Insert", para);
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoZone", "Zone objZone", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }

        public bool Update(Zone objZone)
        {
            int result = 0;
            clsSQL clsSQL = new clsSQL();
            SqlParameter[] para = new SqlParameter[2];
            try
            {
                para[0] = new SqlParameter(busZone.Name, SqlDbType.NVarChar);
                para[0].Value = clsConvert.StringToDB(objZone.Name);
                para[1] = new SqlParameter(busZone.ZoneId, SqlDbType.Int);
                para[1].Value = objZone.ZoneId;
                result = clsSQL.SPExecute("Zone_Update", para);
            }
            catch (Exception ex)
            {
                clsFile.WriteLog("daoZone", "Update(Zone objZone)", ex.ToString());
            }
            finally
            {
                clsSQL.Dispose();
                clsSQL = null;
            }
            if (result > 0)
                return true;
            return false;
        }

    }
}


